Skip to content

Conversation

@BadisLaffet1
Copy link
Contributor

📖 (docs): Limit code rendering to relevant sections in multiversion webhook tutorial

Fixes #5232

Problem

The multiversion webhook tutorial was showing entire file contents instead of only the relevant code sections:

  • Webhook v2: The entire webhook file was rendered, including imports, defaulting logic, and webhook setup
  • main.go: Too much boilerplate was visible instead of focusing on the relevant setup sections

Root Cause

The generation scripts in hack/docs/internal/multiversion-tutorial/ were missing collapse markers to hide non-essential code from the rendered documentation.

Changes Made

File 1: hack/docs/internal/multiversion-tutorial/generate_multiversion.go

updateWebhookV2() function - Added imports collapse marker:

	// Add collapse marker after the import block to hide imports
	err = pluginutil.InsertCode(
		filepath.Join(sp.ctx.Dir, path),
		`batchv2 "tutorial.kubebuilder.io/project/api/v2"
)`,
		`

// +kubebuilder:docs-gen:collapse=Imports`)
	hackutils.CheckError("adding imports collapse marker to webhook v2", err)

updateMain() function - Added Manager Setup collapse marker (Lin:

	err = pluginutil.InsertCode(
		filepath.Join(sp.ctx.Dir, path),
		`if !enableHTTP2 {
		tlsOpts = append(tlsOpts, disableHTTP2)
	}`,
		`

	// +kubebuilder:docs-gen:collapse=Manager Setup`,
	)
	hackutils.CheckError("adding manager setup collapse marker main.go", err)

updateMain() function - Removed existing setup doc marker insertion :

	err = pluginutil.InsertCode(
		filepath.Join(sp.ctx.Dir, path),
		`if err := (&controller.CronJobReconciler{
		Client: mgr.GetClient(),
		Scheme: mgr.GetScheme(),
	}).SetupWithManager(mgr); err != nil {
		setupLog.Error(err, "unable to create controller", "controller", "CronJob")
		os.Exit(1)
	}`,
		`
 `,
	)
	hackutils.CheckError("insert doc marker existing setup main.go", err)

File 2: hack/docs/internal/multiversion-tutorial/webhook_v2_implementaton.go

cronJobValidationFunction constant - Added collapse marker before validation functions :

 const cronJobValidationFunction = `
+// +kubebuilder:docs-gen:collapse=Webhook Setup and Defaulting

 // validateCronJob validates the fields of a CronJob object.
 func validateCronJob(cronjob *batchv2.CronJob) error {

Result

Webhook v2 (cronjob_webhook.go)

  • Collapsed: Apache License, Imports, Webhook Setup and Defaulting
  • Visible: Only validation functions (validateCronJob, validateCronJobName, validateCronJobSpec, validateScheduleFormat)
Screenshot from 2026-01-14 21-26-23

main.go

  • Collapsed: Apache License, Imports, existing setup, Manager Setup (flags and HTTP2 config)
  • Visible: Webhook TLS options, metrics server options, manager creation, controller setup, and webhook registration
Screenshot from 2026-01-14 21-25-26

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jan 14, 2026
@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jan 14, 2026
@k8s-ci-robot
Copy link
Contributor

Hi @BadisLaffet1. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jan 14, 2026
Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

Terrific !!!
Thank you a lot for the amazing work 🎉

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 14, 2026
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: BadisLaffet1, camilamacedo86

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 14, 2026
@vitorfloriano
Copy link
Contributor

/lgtm

Thank you!

@camilamacedo86 camilamacedo86 merged commit 6e7e853 into kubernetes-sigs:master Jan 14, 2026
24 of 28 checks passed
@k8s-ci-robot
Copy link
Contributor

@BadisLaffet1: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubebuilder-e2e-k8s-1-33-0 d5aa585 link unknown /test pull-kubebuilder-e2e-k8s-1-33-0
pull-kubebuilder-e2e-k8s-1-35-0 d5aa585 link unknown /test pull-kubebuilder-e2e-k8s-1-35-0

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docs: Limit code rendering to relevant sections in multiversion webhook tutorial

4 participants